<script setup>

import MyNav from "../../../components/MyNav.vue";
import {insertApi, listApi} from "../../../api/axios.js";
import {onMounted, reactive, ref} from "vue";
import {GENDER_OPTIONS, RULE} from "../../../const/index.js";
import {ElMessage} from "element-plus";
import router from "../../../router/index.js";
import MyForm from "../../../components/MyForm.vue";
import {getResponseData} from "../../../request/index.js";

// 路径导航
const navItems = [
  {icon: 'Avatar', label: '用户管理', url: '/Role'},
  {icon: 'UserFilled', label: '角色列表', url: '/Role'},
  {icon: 'Plus', label: '添加新角色'},
]

//  表单项 + 表单值 + 表单规则
let items = ref([
  {label: '角色名称', prop: 'title', required: true, span: 12},
  {span: 12, hidden: true},
  {label: '角色描述', prop: 'info', type: 'textarea'},
])

let params = reactive({});
let rules = {title: RULE.TITLE, info: RULE.INFO};

/* ================= 添加成功后 ================= */
function insertSuccess() {
  ElMessage.success("添加记录成功！");
  setTimeout(() => router.push('/Role'), 1000);
}

</script>

<template>
  <my-nav :items="navItems"/>
  <el-card class="role-insert-card" header="添加新角色">
    <my-form type="insert"
             :items="items"
             :params="params"
             :rules="rules"
             :api="insertApi"
             :args="{module: 'role'}"
             :callback="insertSuccess"/>
  </el-card>
</template>

<style scoped lang="scss">
.role-insert-card {
  width: 60%; // 宽度
  margin: 65px auto 0; // 居中
}
</style>